// 防抖
export const debounce = function(fn, delay = 500) {
	let timer;
	//  闭包
	return function() {
		const that = this;
		let args = arguments;
		if (timer) {
			clearTimeout(timer)
		}
		timer = setTimeout(function() {
			fn.apply(that, args)
		}, delay)
	}
}


// 节流
export const throttle = function(fn, delay = 500) {
	let timer = null;
	// 返回新的函数
	return function() {
		const that = this
		let args = arguments;

		if (!timer) {
			timer = setTimeout(() => {
				fn.apply(that, args)
				timer = null;
			}, delay)
		}
	}
}